// src/composables/useTranslate.ts
import api from "@/server/index";

export interface TranslateParams {
  q: string; // 要翻译的文本
  source: string; // 源语言，如 'en'
  target: string; // 目标语言，如 'zh'
}

export interface TranslateResponse {
  translatedText: string;
}

/**
 * 调用 LibreTranslate 公开 API
 */
export async function translateText(params: TranslateParams): Promise<string> {
  console.log(api);

  const res: TranslateResponse = await api("/translate", {
    method: "POST",
    body: params,
  });
  return res.translatedText;
}
